var goodsComposeConlums = {
    classConlums : [
        {
            field: 'check',
            checkbox: true,
            class: 'tableCheckStatus',
        },{
            field: 'Number',class: 'tableNumber',//可不加
            title: '序号',
            align: 'center',
            valign: 'top',
            width: '15px',
            formatter: function (v,r,i) {
                return tableNumber(i);
            }
        }, {
            field: 'learningClassName',
            title: '培训类型',
            align: 'center',
            valign: 'top',
            width: '45',
            class: 'over_hidden',
            title_attr: true,
            formatter:function(v,r,i){
                return v;
            }
        }, {
            field: 'name',
            title: '班级名称',
            align: 'center',
            valign: 'top',
            class: 'over_hidden',
            title_attr: true,
            width: '50'
        }
        // {
        //     field: 'handle',
        //     title: '操作',
        //     align: 'center',
        //     valign: 'top',
        //     class: 'over_hidden',
        //     //title_attr: true,
        //     width: '50',
        //     formatter:function(v,r,i){
        //         return '<button type="button" class="layui-btn layui-btn-xs layui-btn-danger" onclick="deleteRow(\'class\',\''+r.composeClassId+'\')">删除</button>';
        //     }
        // }
        ],
    papgerConlums : [
        {
            field: 'check',
            checkbox: true,
            class: 'tableCheckStatus',
        },{
            field: 'Number',class: 'tableNumber',//可不加
            title: '序号',
            align: 'center',
            valign: 'top',
            width: '15px',
            formatter: function (v,r,i) {
                return tableNumber(i);
            }
        }, {
            field: 'paperTypeName',
            title: '类型',
            align: 'center',
            valign: 'top',
            width: '45',
            class: 'over_hidden',
            title_attr: true,
            formatter:function(v,r,i){
                return v;
            }
        }, {
            field: 'name',
            title: '名称',
            align: 'center',
            valign: 'top',
            class: 'over_hidden',
            title_attr: true,
            width: '50'
        }
        // , {
        //     field: 'handle',
        //     title: '操作',
        //     align: 'center',
        //     valign: 'top',
        //     class: 'over_hidden',
        //     // title_attr: true,
        //     width: '50',
        //     formatter:function(v,r,i){
        //         return '<button type="button" class="layui-btn layui-btn-xs layui-btn-danger" onclick="deleteRow(\'paper\',\''+r.composePaperId+'\')">删除</button>';
        //     }
        // }
        ],
    bookConlums : [
        {
            field: 'check',
            checkbox: true,
            class: 'tableCheckStatus',
        },{
            field: 'Number',class: 'tableNumber',//可不加
            title: '序号',
            align: 'center',
            valign: 'top',
            width: '15px',
            formatter: function (v,r,i) {
                return tableNumber(i);
            }
        }, {
            field: 'name',
            title: '书籍名称',
            align: 'center',
            valign: 'top',
            width: '45',
            class: 'over_hidden',
            title_attr: true,
            formatter:function(v,r,i){
                return v;
            }
        }, {
            field: 'bookClassName',
            title: '类型',
            align: 'center',
            valign: 'top',
            class: 'over_hidden',
            title_attr: true,
            width: '50'
        }
        // , {
        //     field: 'handle',
        //     title: '操作',
        //     align: 'center',
        //     valign: 'top',
        //     class: 'over_hidden',
        //     // title_attr: true,
        //     width: '50',
        //     formatter:function(v,r,i){
        //         return '<button type="button" class="layui-btn layui-btn-xs layui-btn-danger" onclick="deleteRow(\'book\',\''+r.composeBookId+'\')">删除</button>';
        //     }
        // }
        ]
}

var base_fun = {
    onlyRead : function (){
        $("input").prop("placeholder", "");
        $("input").addClass("layui-disabled");
        $("input").attr("disabled", "disabled");
        $("textarea").prop("placeholder", "");
        $("textarea").addClass("layui-disabled");
        $("textarea").attr("disabled", "disabled");
        $("select").addClass("layui-disabled");
        $("select").attr("disabled", "disabled");

        if(editor){
            editor.readonly(true);
        }
    }
}

function publishPro(state){
    if(!state && state != 0){
        return false;
    }
    var row = select_one_row();
    var stateName = state ? '上架' : '下架';
    if(row.state == state){
        layerMessage('该套餐已'+stateName+'，无需重复操作！', 2);
        return false;
    }
    if (row) {
        Layui.confirm("是否确定"+stateName+"该套餐？", '', function(layer, index) {
            var data = This.jqueryAjax(Api.stu.goodsCompose.common.publishById, {id: row.composeId, state : state});
            if (data.status == 1) {
                layerMessage(data.message);
                closeFlushParent(parent);
            } else if (data.status == -1) {
                layerMessage(data.message, 2);
            }
        });
    }
}

function format(value,formatString) {
    if(!value){
        return "";
    }
    formatString = formatString || 'YYYY-MM-DD';
    if(typeof value=="string" && value.indexOf("T")>-1){
        return moment(value, moment.ISO_8601).format(formatString);
    }
    return moment(value).format(formatString); // 这是时间戳转时间(毫秒)
}

// 校验选择信息

function checkSelect(type) {
    var classCount = $('#table_list_class').bootstrapTable('getData').length;
    var bookCount = $('#table_list_book').bootstrapTable('getData').length;
    var paperCount = $('#table_list_paper').bootstrapTable('getData').length;
    if(type == 'class'){
        return classCount;
    }
    if(type == 'book'){
        return bookCount;
    }
    if(type == 'paper'){
        return paperCount;
    }
    return 0;
}

function deleteRow(type,idCode){
    var row = select_one_row('table_list_'+type);
    if (!row) {
        return false;
    }
    var id = row[idCode];
    Layui.confirm("是否确定删除？", {
        btn: ['确定', '取消']
    }, function (index) {
        layer.close(index);
        // 选择后直接保存
        This.jqueryAjax(Url.creatUrl(Api.stu.goodsCompose.common['delete_'+type]) , {id : id}, "json", function (data) {
            if (data && data.status == 1) {
                init_table_search(null, 'table_list_'+type);
            } else {
                layerMessage(data.message, 2);
            }
        });
    },'0');
    return false;
}

function initTags(val){
    This.jqueryAjax(Api.base.dataDictionary.getDataDictionaryDetailListByCode, {code : JSON.stringify([{ "id": "tags", "code": "tags" }])}, "json", function(data){
        var str = '';
        if(data){
            var _data = data.object.tags;
            var checked = '';
            $(_data).each(function (i, ele){
                if(val){
                    checked = '';
                    if(val.indexOf(ele.name+',') != -1){
                        checked = 'checked';
                    }
                }
                str += '<input type="checkbox" name="tags" title="'+ele.name+'" lay-skin="primary" value="'+ele.name+'" '+checked+'>';
            })
            $('#tags').append(str);
            layform.render("checkbox");
        }
    });
}





